window.SystemInfo = (function(){

    var _static = {
        platform: null,//运行平台
        logInfo: "INFO",//日志级别， INFO /DEBUG /NONE /ERROR
        gameQuery: null,//进游戏带的参数
        isRunning: false, //是否在游戏中
        runInIphoneX: false, //是否在iphoneX平台上运行
        isPlayingVideo:false,//是否正在播放video


        /**
         * 设置平台
         */
        setPlatform: function () { //暂时只做简单判断，wx/other
            if (cc.sys.platform == cc.sys.MACOS) {
                this.platform = "macOs";
            }
            else if (cc.sys.platform == cc.sys.ANDROID) {
                this.platform = "android";
            }
            else if (cc.sys.platform == cc.sys.IPHONE) {
                this.platform = "iphone";
            }
            else if (cc.sys.platform == cc.sys.IPAD) {
                this.platform = "ipad";
            }
            else if (cc.sys.platform == cc.sys.MOBILE_BROWSER) {
                this.platform = "mobileBrowser";//手机流浪器
            }
            else if (cc.sys.platform == cc.sys.DESKTOP_BROWSER) {
                this.platform = "desktopBrowser";//桌面流浪器
            }
            else if (cc.sys.platform == cc.sys.WECHAT_GAME) {
                if (cc.sys.browserType == cc.sys.BROWSER_TYPE_WECHAT_GAME) {
                    this.platform = "weChatGame";
                }
                else {
                    this.platform = "weChat";
                }
            }
            else if (cc.sys.platform == cc.sys.QQ_PLAY) {
                if (cc.sys.browserType == cc.sys.BROWSER_TYPE_QQ_PLAY) {
                    this.platform = "qqPlay";
                }
            }else{
                this.platform = "macOs";
            }
            Log.info("cc.sys.platform:",cc.sys.platform)
            Log.info("当前运行平台是",this.platform)
        },

        getPlatform: function () {
            return this.platform;
        },

        /**
         * 本地缓存
         * @param key
         * @param value
         */
        setLocalStorage: function (key, value) {
            if(this.getPlatform() == "qqPlay"){
                BK.localStorage.setItem(key,value);
            }else{
                cc.sys.localStorage.setItem(key+UserInfo.userId, String(value));
            }
            Log.debug("设置本地存储 key:"+key,"value:"+value)
        },

        getLocalStorage: function (key, defaultValue) {
            var value = this.getPlatform() == "qqPlay"?BK.localStorage.getItem(key):cc.sys.localStorage.getItem(key+UserInfo.userId);
            if (!value) {
                return defaultValue;
            }
            return value;
        },

        /**
         * 日志级别
         * @returns {*}
         */
        getLogInfo: function () {
            return this.logInfo;
        },

        setLogInfo:function(loginfo){
            this.logInfo = loginfo;
        },

        /**
         * 进入游戏的次数
         */
        addGameStartTime:function(){
           let gameTime = this.getLocalStorage("GameStartTime","0");
           this.setLocalStorage("GameStartTime",(parseInt(gameTime)+1).toString());
        },

        getGameStartTime:function(){
            return  parseInt(this.getLocalStorage("GameStartTime","0"));
        },

        /**
         * 开始游戏的次数
         */
        addGameRuningTime:function(){
            let gameTime = this.getLocalStorage("GameRuningTime","0");
            this.setLocalStorage("GameRuningTime",(parseInt(gameTime)+1).toString());
        },

        getGameRuningTime:function(){
            return  parseInt(this.getLocalStorage("GameRuningTime","0"));
        },

        /**
         * 获取游戏中状态
         * @param isRunning
         */
        setIsRunning:function(isRunning){
            this.isRunning = isRunning;
        },
        getIsRunning:function(){
            return this.isRunning;
        },


        /**
         * 是否开启音乐
         * @param isOpenMusic
         */
        setIsOpenMusic:function(isOpenMusic){
            this.setLocalStorage("isOpenMusic",isOpenMusic);
        },
        getIsOpenMusic:function(){
            return this.getLocalStorage("isOpenMusic","true");
        },


        /**
         * 进游戏带的参数
         * @param gameQuery
         */
        setGameQuery:function(gameQuery){
            this.gameQuery = gameQuery;
        },

        getGameQuery:function(){
            return this.gameQuery ;
        },

        setRunInIphoneX:function(runInIphoneX){
            this.runInIphoneX =runInIphoneX;
        },

        getRunInIphoneX:function(){
            return this.runInIphoneX;
        },

        /**
         * 是否正在播放音乐
         * @param isShowingVideo
         */
        setIsPlayingVideo:function(isPlayingVideo){
            this.isPlayingVideo = isPlayingVideo;
        },
        getIsPlayingVideo: function () {
            return this.isPlayingVideo;
        },






    }
    return _static;

})();

module.exports = SystemInfo;